﻿// <copyright file="Map.cs" company="Microsoft Corporation">
// Copyright (c) 2009 Microsoft Corporation All Rights Reserved
// </copyright>
// <author>Michael S. Scherotter</author>
// <email>mischero@microsoft.com</email>
// <date>2008-10-04</date>
// <summary>OpenSocial Map</summary>

namespace opensocial
{
    using System.Windows.Browser;

    /// <summary>
    /// opensocial Map
    /// </summary>
    /// <typeparam name="TKey">the map key</typeparam>
    /// <typeparam name="TValue">the map value</typeparam>
    public class Map<TKey, TValue>
    {
        /// <summary>
        /// Initializes a new instance of the Map class.
        /// </summary>
        /// <param name="scriptObject">a script object</param>
        internal Map(ScriptObject scriptObject)
        {
            this.ScriptObject = scriptObject;
        }

        /// <summary>
        /// Gets or sets the script object
        /// </summary>
        public ScriptObject ScriptObject { get; set; }

        /// <summary>
        /// Map Indexer
        /// </summary>
        /// <param name="key">a key in the map</param>
        /// <returns>the value</returns>
        public TValue this[TKey key]
        {
            get
            {
                var value = this.ScriptObject.InvokeSelf(key);

                return (TValue)value;
            }
        }
    }
}
